package com.example.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.domain.Manager;
import com.example.mapper.ManagerMapper;
import com.example.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
* @author DPH
* @description 针对表【tbl_manager】的数据库操作Service实现
* @createDate 2022-11-23 16:21:00
*/
@Service
public class ManagerServiceImpl extends ServiceImpl<ManagerMapper, Manager>
    implements ManagerService{
    @Autowired
    private ManagerMapper managerMapper;

    @Override
    public boolean login(String username, String password) {
        Manager manager = managerMapper.selectById(username);
        return manager != null && manager.getPassword().equals(password);
    }

    @Override
    public IPage<Manager> getManagers(int currentPage, int pageSize) {
        IPage page = new Page(currentPage,pageSize);
        managerMapper.selectPage(page,null);
        return page;

    }


    @Override
    public boolean add(Manager manager) {
        return managerMapper.insert(manager) > 0;
    }

    @Override
    public boolean delete(String username) {
        return managerMapper.deleteById(username) > 0;
    }

    @Override
    public Manager findByUsername(String username) {
        return managerMapper.selectById(username);
    }

    @Override
    public Manager modify(Manager manager) {
        return managerMapper.updateById(manager) > 0 ? manager : null;
    }

    @Override
    public int getManagerCount() {
        return Math.toIntExact(managerMapper.selectCount(null));
    }
}




